using System.Reflection;

namespace DynamicLogicExpression;

public class PropertyNavigation : IEquatable<PropertyNavigation?>
{
    public PropertyInfo PropertyInfo { get; set; } = null!;

    public string Navigation { get; set; } = null!;

    public PropertyNavigation? SubNavigation { get; set; }

    public override bool Equals(object? obj)
    {
        return Equals(obj as PropertyNavigation);
    }

    public bool Equals(PropertyNavigation? other)
    {
        return other is not null &&
               EqualityComparer<PropertyInfo>.Default.Equals(PropertyInfo, other.PropertyInfo) &&
               Navigation == other.Navigation &&
               EqualityComparer<PropertyNavigation?>.Default.Equals(SubNavigation, other.SubNavigation);
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(PropertyInfo, Navigation, SubNavigation);
    }

    public static bool operator ==(PropertyNavigation? left, PropertyNavigation? right)
    {
        return EqualityComparer<PropertyNavigation>.Default.Equals(left, right);
    }

    public static bool operator !=(PropertyNavigation? left, PropertyNavigation? right)
    {
        return !(left == right);
    }
}